﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using OgilvyOne.UKNow.Mobile.Model.Events;
using OgilvyOne.UKNow.Configuration;
using OgilvyOne.UKNow.Model;

namespace OgilvyOne.UKNow.Mobile.APIs
{
    public class APIComm
    {
        public string ObjToJson<T>(T t, Dictionary<string, string> proArr)
        {
            Type obj = t.GetType();

            StringBuilder jsn = new StringBuilder();
            jsn.Append("{");

            foreach (string pro in proArr.Keys)
            {
                PropertyInfo prop = obj.GetProperty(proArr[pro]);
                Object o = prop.GetValue(t, null);
                if (o != null)
                {
                    jsn.AppendFormat("'{0}':'{1}',", pro, o.ToString());
                }

            }
            string str = jsn.ToString();
            if (str.Length != 0)
            {
                str = str.Substring(0, str.Length - 1);
            }

            str = str + "}";

            return str;
        }



        public List<PhoneImage> DirToLisO(Dictionary<string, string> dir)
        {
            if (dir == null)
            {
                return null;
            }
            else
            {
                List<PhoneImage> lpi = new List<PhoneImage>();
                foreach (string str in dir.Keys)
                {
                    PhoneImage pi = new PhoneImage();
                    pi.Imagpath = ConfigCacheManager.DomainName + ConfigCacheManager.FilePath.GetImageVirtualPath(str);
                    pi.Imagename = dir[str];
                    lpi.Add(pi);

                }
                return lpi;
            }
        }
    }
}
